package com.programmeur.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import static com.programmeur.dao.DAOUtilitaire.*;
import com.programmeur.beans.News;

public class NewsDaoImpl implements NewsDao {
	DAOFactory daofactory;
	private static final String SQL_SELECT_PAR_TITRE = "SELECT id,texte,image from news where titre=?";

	@Override
	public void Creer(News news) throws DAOException {
		// TODO Auto-generated method stub

	}

	public NewsDaoImpl(DAOFactory daofactory) {
		this.daofactory = daofactory;

	}

	@Override
	public void Supprimer(int id) throws DAOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void Modifier(int id) throws DAOException {
		// TODO Auto-generated method stub

	}

	@Override
	public List<News> ToutLesNews() throws DAOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<News> DerniersNews() throws DAOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public News TrouverNews(String titre) throws DAOException {
		// TODO Auto-generated method stub
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		News news = null;
		try {
			connection = daofactory.getConnection();
			preparedStatement = initialisationRequetePreparee(connection,
					SQL_SELECT_PAR_TITRE, false, titre);
			resultSet = preparedStatement.executeQuery();
			if (resultSet.next()) {
				news = map(resultSet);
			}
		} catch (SQLException e) {

		}
		return null;
	}

}
